package cn.ac.iie.bdb_to_mongo.receiver;

import cn.ac.iie.di.datadock.rdata.exchange.client.core.session.receive.REAbstractReceiveMessageHandler;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.REMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.BlockingQueue;

/**
 * @auther Fighter Created on 2016/12/2.
 */
public class MessageSuccessReceiver extends REAbstractReceiveMessageHandler<REMessage> {

    private final Logger LOG = LoggerFactory.getLogger(MessageSuccessReceiver.class);
    BlockingQueue<REMessage> queue;

    public MessageSuccessReceiver(BlockingQueue queue) {
        this.queue = queue;
    }

    @Override
    public boolean handle(REMessage message) {
        boolean isSuccess = queue.offer(message);
        if (!isSuccess) {
//            LOG.warn("cn.ac.iie.bdb_to_mongo.receiver queue is full,please decrease handler thread " + "or increase mq consumer thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
        return isSuccess;
    }
}
